package com.printeverywhere.ImpComparator;

import java.util.Comparator;

import com.printeverywhere.dto.Items;
import com.printeverywhere.dto.MailServer;

public class SortItem {

	public class SortByTime implements Comparator<Items> {
		public int compare(Items objOne, Items objTwo) {
		        return objOne.getEndTime().compareTo(objTwo.getEndTime());
		}
	}

	public class SortByTitle implements Comparator<Items> {
		public int compare(Items objOne, Items objTwo) {
		        return objOne.getTitle().compareTo(objTwo.getTitle());
		}
	}

	public class SortByBuyPrice implements Comparator<Items> {
		public int compare(Items objOne, Items objTwo) {
		        return objOne.getBuyPrice().compareTo(objTwo.getBuyPrice());
		}
	}

	public class SortByBidSize implements Comparator<Items> {
		public int compare(Items objOne, Items objTwo) {
				Integer sizeForObjOne = objOne.getBids().size();
				Integer sizeForObjTwo = objTwo.getBids().size();
		        return sizeForObjOne.compareTo(sizeForObjTwo);
		}
	}

	public class SortByImage implements Comparator<Items> {
		public int compare(Items objOne, Items objTwo) {
			Integer lengthForObjOne = 0;
			Integer lengthForObjTwo = 0;
				if(objOne.getThumbImage() == null && objOne.getThumbImage().length <=0){
					lengthForObjOne = 0;
				}else{
					lengthForObjOne = objOne.getThumbImage().length;
				}
				if(objTwo.getThumbImage() == null && objTwo.getThumbImage().length <=0){
					lengthForObjTwo = 0;
				}else{
					lengthForObjTwo = objTwo.getThumbImage().length;
				}
		        return lengthForObjOne.compareTo(lengthForObjTwo);
		}
	}

	public class SortMailByReciveDate implements Comparator<MailServer> {
		public int compare(MailServer objOne, MailServer objTwo) {
		        return objOne.getCreatedOn().compareTo(objTwo.getCreatedOn());
		}
	}
}
